//
//  ThirdViewController.m
//  视图控制器的生命周期
//
//  Created by 伍银荣 on 2021/6/23.
//  Copyright © 2021 com.example. All rights reserved.
//

#import "ThirdViewController.h"

@interface ThirdViewController ()

@end

@implementation ThirdViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"ThirdVC";
    self.view.backgroundColor = [UIColor blueColor];
    
    UIButton *btn = [[UIButton alloc]initWithFrame:CGRectMake(100, 200, 200, 40)];
    [btn setTitle:@"跳转到根控制器" forState:UIControlStateNormal];
    [self.view addSubview:btn];
    [btn addTarget:self action:@selector(btnClicked) forControlEvents:UIControlEventTouchUpInside];
    
    UIButton *btn2 = [[UIButton alloc]initWithFrame:CGRectMake(100, 400, 200, 40)];
    [btn2 setTitle:@"跳转到指定控制器" forState:UIControlStateNormal];
    [self.view addSubview:btn2];
    [btn2 addTarget:self action:@selector(btn2Clicked) forControlEvents:UIControlEventTouchUpInside];
    
}

- (void)btnClicked {
    NSLog(@"跳转到根控制器");
    [self.navigationController popToRootViewControllerAnimated:YES];
}

- (void)btn2Clicked {
    NSLog(@"跳转到指定控制器");
    NSArray *vcs = self.navigationController.viewControllers;
    [self.navigationController popToViewController:vcs[1] animated:YES];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
